//
//  IWHomeViewCtrl.m
//  WeiBo17
//
//  Created by teacher on 15/8/16.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "IWHomeViewCtrl.h"
#import "IWTitleButton.h"
#import "IWPopMenuView.h"
#import "IWTemp2Ctrl.h"

@interface IWHomeViewCtrl ()

@end

@implementation IWHomeViewCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置导航栏的内容
    [self setNav];
    
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, 100, 40)];
    [button setBackgroundColor:[UIColor redColor]];
    [button addTarget:self action:@selector(titleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

/**
 *  设置导航栏的内容
 */
- (void)setNav{
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"navigationbar_friendsearch" target:self action:@selector(friendsearch)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImageName:@"navigationbar_pop" target:self action:@selector(pop)];
    
    IWTitleButton *titleBtn = [[IWTitleButton alloc] init];
    //设置标题与图片
    [titleBtn setTitle:@"我叫首页" forState:UIControlStateNormal];
    [titleBtn setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
    titleBtn.backgroundColor = [UIColor redColor];
    
    //设置文字颜色
    [titleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [titleBtn sizeToFit];
    
    //添加点击事件
    [titleBtn addTarget:self action:@selector(titleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.titleView = titleBtn;
}


- (void)titleButtonClick:(IWTitleButton *)button{
    //自定义的view
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(5, 12, 100, 100)];
    //设置背景颜色
    customView.backgroundColor = [UIColor redColor];
    
    //初始化一个pop菜单
    IWPopMenuView *popMneu = [[IWPopMenuView alloc] initWithCustomView:customView];
    [popMneu showWithView:button];
    //初始化小灰框
//    UIImageView *imageView = [[UIImageView alloc] init];
    
//    UIImage *image = [UIImage imageNamed:@"popover_background"];
//    imageView.image = image;
//    imageView.size = CGSizeMake(110, 120);
    

    
//    [imageView addSubview:customView];
    
    
    //前一步添加是拿着button的位置直接去计算的,而这个button的位置是相对于其父控件来说的,而我们要添加的imageView的位置是相对于屏幕来说,所以说,这两个控件不是在同一步坐标系里面,然后我就调用convertRect把button的位置与大小转到屏幕上面去
    
//    UIWindow *window = [UIApplication sharedApplication].keyWindow;
//    //把button的坐标转换到屏幕坐标
////    __ convertRect:__ toView:__
//    CGRect rect = [button convertRect:button.bounds toView:window];
//    
//    imageView.centerX = CGRectGetMidX(rect);
//    imageView.y = CGRectGetMaxY(rect);
//    
//    [window addSubview:imageView];
    
    
    
}

- (void)friendsearch{
    NSLog(@"%s",__func__);
    IWTemp2Ctrl *ctrl = [IWTemp2Ctrl new];
    
    //在push当前控制器的时候,指定底部的TabBar隐藏
//    ctrl.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:ctrl animated:YES];
    
}

- (void)pop{
//    NSArray *array = [NSArray arrayWithObject:@"哈哈"];
//    
//    NSLog(@"%@",array[1]);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
